package com.example.demo.Util;

import java.text.SimpleDateFormat;
import java.util.regex.Pattern;

public class UserUtil {
    private static UserUtil instance;

    private UserUtil() {
    }

    public static UserUtil getInstance() {
        if (instance == null) instance = new UserUtil();
        return instance;
    }

    private static String strDateFormat = "yyyy-MM-dd HH:mm:ss";
    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(strDateFormat);

    public static SimpleDateFormat getSimpleDateFormat() {
        return simpleDateFormat;
    }


    public static boolean checkUserID(String uid) {
        String regex = "^[a-zA-Z][a-zA-Z0-9_]{2,15}$";
        Pattern pattern = Pattern.compile(regex);
        return pattern.matcher(uid).matches();
    }

    public static boolean checkUserEmail(String email) {
        String regex = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
        Pattern pattern = Pattern.compile(regex);
        return pattern.matcher(email).matches();
    }

    public static boolean checkUserVerificationCode(String code) {
        String regex = "^\\d{6}$";
        Pattern pattern = Pattern.compile(regex);
        return pattern.matcher(code).matches();
    }

    public static boolean checkUserPassword(String password) {
        String regex = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$";
        Pattern pattern = Pattern.compile(regex);
        return pattern.matcher(password).matches();
    }
}
